package com.aipanda.pojo;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import java.io.Serializable;

/**
 * @param property 属性
 * @param direction 方向[排序方向]
 * @author wanyuxiang
 * 
 */
public class SQLSequence implements Serializable {
	private static final long serialVersionUID = -3078342809727773232L;
	private String property;
	private Direction direction = Direction.desc;

	public SQLSequence() {
	}
	
	/**
	 * @param asc	递增	
	 * @param desc 	递减
	 * @author wanyuxiang
	 *
	 */
	public enum Direction {
		asc, desc;

	public static Direction fromString(String value) {
		return valueOf(value.toLowerCase());
	}
	}

	public SQLSequence(String property, Direction direction) {
		this.property = property;
		this.direction = direction;
	}

	public static SQLSequence asc(String property) {
		return new SQLSequence(property, Direction.asc);
	}

	public static SQLSequence desc(String property) {
		return new SQLSequence(property, Direction.desc);
	}

	public String getProperty() {
		return this.property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public Direction getDirection() {
		return this.direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		SQLSequence order = (SQLSequence) obj;
		return new EqualsBuilder().append(getProperty(),order.getProperty()).append(getDirection(),order.getDirection()).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(getProperty()).append(getDirection()).toHashCode();
	}
}
